//
//  MSMemberServeTableVC.m
//  SocietySale
//
//  Created by Mike on 16/11/18.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSMemberServeTableVC.h"
#import "MSMemberServeCell.h"

@interface MSMemberServeTableVC ()

@end

@implementation MSMemberServeTableVC

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellId = @"cellId";
    MSMemberServeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[MSMemberServeCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == [self.dataArray count]-1) {
        cell.horizonLineView.frame = CGRectMake(0, 49.4, SCREEN_WIDTH, 0.6);
    }
    else{
        cell.horizonLineView.frame = CGRectMake(12, 49.4, SCREEN_WIDTH-24, 0.6);
    }
    cell.delegate = (id)self.delegate;
    cell.rowIndex = indexPath.row;
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 48;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    bgView.backgroundColor = kDefaultViewBackgroundColor;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12, 15, 200, 30)];
    label.font = HeitiFont(15);
    label.textColor = [UIColor blackColor];
    label.text = @"江湖币可以做什么？";
    [bgView addSubview:label];
    
    NSMutableAttributedString *priceAttstr = [[NSMutableAttributedString alloc] initWithString:@"江湖币余额:  X" attributes:@{NSFontAttributeName:HeitiFont(13),NSForegroundColorAttributeName:kDarkGrayColor}];
    
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment.bounds = CGRectMake(0, -4, 17, 17);
    textAttachment.image = [UIImage imageNamed:@"coin"];
    NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
    [priceAttstr insertAttributedString:attachmentString atIndex:7];
    
    NSAttributedString *priStr = [[NSAttributedString alloc] initWithString:[HDUtil check:_serveModel.wallet] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor blackColor]}];
    [priceAttstr appendAttributedString:priStr];
    
    label.attributedText = priceAttstr;
    
    CGSize size = [HDUtil sizeWithString:priceAttstr size:CGSizeMake(200, 15)];
    
    if ([_serveModel.wallet integerValue]<10) {
        UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(size.width+22, 22.5, 166, 15)];
        tipLabel.font = HeitiFont(13);
        tipLabel.textColor = UIColorFromRGB(0xb33630);
        tipLabel.text = @"余额不足，快去赚江湖币吧!";
        tipLabel.backgroundColor = UIColorFromRGB(0xf4e7e3);
        [bgView addSubview:tipLabel];
    }
    
    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 8;
}

@end
